package com.baiyun.lease.web.admin.schedule;

import com.baiyun.lease.model.entity.LeaseAgreement;
import com.baiyun.lease.model.enums.LeaseStatus;
import com.baiyun.lease.web.admin.service.LeaseAgreementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: 许瑞淇
 * @Date: 2024/06/16/11:41
 * @Description: 定时任务检查租约是否到期
 */
@Component
public class ScheduledTasks {
    @Autowired
    private LeaseAgreementService leaseAgreementService;

    @Scheduled(cron = "0 0 0 * * *")
    public void ScheduleStatus(){
        Date date = new Date();
        leaseAgreementService.lambdaUpdate()
                .le(LeaseAgreement::getLeaseEndDate,date)
                .in(LeaseAgreement::getStatus, LeaseStatus.SIGNED,LeaseStatus.WITHDRAWING)
                .set(LeaseAgreement::getStatus, LeaseStatus.EXPIRED)
                .update();

    }
}
